package cn.edu.scau.cmi.zhangmingxing.adapter;

import java.util.ArrayList;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;

public class AdapterController {
	ArrayList<Student> students = new ArrayList<Student>();
	ArrayList<Integer> studentNumbers = new ArrayList<Integer>();
	Target classTarget = new AdapterOfClass();
	Target ObjectTarget = new AdapterOfObject();

	@FXML
	private TextArea area;

	@FXML
	private Button ClassAdapter;

	@FXML
	private Button ObjectAdapter;

	@FXML
	private Button sure;

	@FXML
	private TextField fieldName;

	@FXML
	private TextField fieldNumber;

	private int choice = 0;

	@FXML
	void ClassAdapterButton(ActionEvent event) {
		choice = 0;
	}

	@FXML
	void ObjectAdapterButton(ActionEvent event) {
		choice = 1;
	}

	@FXML
	void input(ActionEvent event) {
		if (choice == 0) {

			classTarget.sortStudent(students, studentNumbers, Integer.parseInt(fieldNumber.getText()),
					fieldName.getText());
			area.clear();
			for (int i = 0; i < students.size(); i++) {
				area.appendText(students.get(i).getNumber() + "    " + students.get(i).getName() + '\n');
			}
		} else {
			ObjectTarget.sortStudent(students, studentNumbers, Integer.parseInt(fieldNumber.getText()),
					fieldName.getText());
			area.clear();
			for (int i = 0; i < students.size(); i++) {
				area.appendText(students.get(i).getNumber() + "    " + students.get(i).getName() + '\n');
			}

		}
	}

}
